package io.renren.modules.book.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String EXCHANGE_DIRECT_HUANG = "direct.huang";//direct类型交换机
    public static final String QUEUE_1 = "queue1";
    public static final String ROUTINGKEY_DIRECT_HUANG = "huang";

    //声明交换机
    @Bean(EXCHANGE_DIRECT_HUANG)
    public DirectExchange directExchange(){
        return ExchangeBuilder.directExchange(EXCHANGE_DIRECT_HUANG).durable(false).build();
    }

    //声明队列
    /*
     *   new Queue(QUEUE_EMAIL,true,false,false)
     *   durable="true" 持久化 rabbitmq重启的时候不需要创建新的队列
     *   auto-delete 表示消息队列没有在使用时将被自动删除 默认是false
     *   exclusive  表示该消息队列是否只在当前connection生效,默认是false
     */
    @Bean(QUEUE_1)
    public Queue queue(){
        return new Queue(QUEUE_1, false, false, false);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(directExchange()).with(ROUTINGKEY_DIRECT_HUANG);
    }
}
